package com.qianxx.view.xrecyclerview;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qianxx.base.R;

/**
 * Created by Administrator on 2017/6/16.
 * <p>
 * 网络异常出错代码重试
 */
public class XFooterView extends LinearLayout implements IFooterListener {

    private TextView mTvFooter;
    private LinearLoading mXLoadView;

    public XFooterView(Context context) {
        this(context, null);
    }

    public XFooterView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public XFooterView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        init(context);
    }

    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.x_footer_view, this);

        setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        mTvFooter = (TextView) findViewById(R.id.tv_footer);
        mXLoadView = (LinearLoading) findViewById(R.id.x_load_view);

        // 默认不显示
        setVisibility(GONE);
    }

    @Override
    public void hideView() {
        setVisibility(GONE);
    }

    @Override
    public void initView() {
        setVisibility(VISIBLE);
        mTvFooter.setText("上拉加载更多...");
        mXLoadView.hideLoading();
    }

    @Override
    public void loading() {
        mTvFooter.setText("正在加载...");
        mXLoadView.showLoading();
    }

    @Override
    public void loadComplete() {
        mTvFooter.setText("加载完成");
        mXLoadView.hideLoading();
    }

    @Override
    public void loadFailed() {
        mTvFooter.setText("加载失败");
        mXLoadView.hideLoading();
    }
}
